package com.handyshop.mall.gateway.vo;

import com.handyshop.mall.gateway.constants.ErrorEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 * web返回实体
 *
 * @author handy
 * @date 2019/8/22 15:18
 */
@Data
@ApiModel(value = "返回码")
public class TokenResultVo<T> implements Serializable {
    @ApiModelProperty(value = "返回编码")
    private String code;
    @ApiModelProperty(value = "返回消息")
    private String msg;
    @ApiModelProperty(value = "返回数据")
    private T data;

    public TokenResultVo() {
    }

    private TokenResultVo(ErrorEnum errorEnum) {
        this.code = errorEnum.getCode();
        this.msg = errorEnum.getMsg();
    }

    private TokenResultVo(ErrorEnum errorEnum, String msg) {
        this.code = errorEnum.getCode();
        this.msg = msg;
    }

    private TokenResultVo(ErrorEnum errorEnum, T data) {
        this.code = errorEnum.getCode();
        this.msg = errorEnum.getMsg();
        this.data = data;
    }

    public static <T> TokenResultVo<T> success() {
        return new TokenResultVo<T>(ErrorEnum.SUCCESS);
    }

    public static <T> TokenResultVo<T> success(String msg) {
        return new TokenResultVo<>(ErrorEnum.SUCCESS, msg);
    }

    public static <T> TokenResultVo<T> success(T data) {
        return new TokenResultVo<>(ErrorEnum.SUCCESS, data);
    }

    public static <T> TokenResultVo<T> failure(ErrorEnum errorEnum) {
        return new TokenResultVo<T>(errorEnum);
    }

    public static <T> TokenResultVo<T> failure(ErrorEnum errorEnum, String msg) {
        return new TokenResultVo<T>(errorEnum, msg);
    }

    public static <T> TokenResultVo<T> failure(ErrorEnum errorEnum, T data) {
        return new TokenResultVo<T>(errorEnum, data);
    }

}